import csv
import openpyxl
from pathlib import Path
import zipfile

class Read:
    def __init__(self, filepath):
        self.filepath = filepath


class CsvRead(Read):
    def __init__(self, filepath):
        super().__init__(filepath)

    def read(self):
        with open(self.filepath, encoding="utf-8-sig") as f:
            filereader = csv.reader(f)
            filedata = list(filereader)
        return filedata


class ExcelRead(Read):
    def __init__(self, filepath):
        super().__init__(filepath)

    def read(self):
        wb = openpyxl.load_workbook(self.filepath)
        sheet = wb.active
        column1 = list(sheet.columns)[0][1:]
        column2 = list(sheet.columns)[1][1:]
        data1 = []
        data2 = []
        for i in column1:
            data1.append(i.value)
        for j in column2:
            data2.append(j.value)
        filedata = list(zip(data1, data2))
        return filedata


class ZipRead(Read):
    def __init__(self, filepath, target_filename):
        super().__init__(filepath)
        self.target_filename = target_filename

    def read(self):
        file_list = zipfile.ZipFile(self.filepath).namelist()
        file_suffix = Path(self.target_filename).suffix
        if self.target_filename in file_list:
            extract_filepath = zipfile.ZipFile(self.filepath).extract(self.target_filename)
            if file_suffix == ".csv":
                filedata = CsvRead(extract_filepath).read()
            if file_suffix == ".xlsx":
                filedata = ExcelRead(extract_filepath).read()
        return filedata
